//
//  LAReviewHeaderViewButton.m
//  LYLazizDevelopDemo
//
//  Created by xbn_iMac on 2016/11/2.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LAReviewHeaderViewButton.h"
#import "Masonry.h"

@interface LAReviewHeaderViewButton ()

@end

@implementation LAReviewHeaderViewButton

-(instancetype)init {
    self = [super init];
    if (self) {
        self.backgroundColor = UIColorFromRGB(0xf6f6f6, 1);
        self.layer.cornerRadius = 4;
        self.layer.borderColor = UIColorFromRGB(0x33a928, 1).CGColor;
        [self createSubView];
    }
    return self;
}

-(void)createSubView {
    self.title = [[UILabel alloc] init];
    self.title.font = [UIFont systemFontOfSize:14];
    [self addSubview:self.title];
    
    self.num = [[UILabel alloc] init];
    self.num.font = [UIFont systemFontOfSize:10];
    [self addSubview:self.num];
    
    self.selected = NO;
    
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self).offset(7);
    }];
    
    [self.num mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self.title.mas_bottom);
    }];
}

-(void)setSelected:(BOOL)selected {
    if (selected) {
        self.title.textColor = UIColorFromRGB(0x33a928, 1);
        self.num.textColor = UIColorFromRGB(0x33a928, 1);
        self.backgroundColor = [UIColor whiteColor];
        self.layer.borderWidth = 0.5;
    }
    else {
        self.title.textColor = UIColorFromRGB(0x666666, 1);
        self.num.textColor = UIColorFromRGB(0x999999, 1);
        self.backgroundColor = UIColorFromRGB(0xf6f6f6, 1);
        self.layer.borderWidth = 0;
    }
}

-(CGSize)intrinsicContentSize {
    
    CGSize size1 = [self.title intrinsicContentSize];
    CGSize size2 = [self.num intrinsicContentSize];
    
    return CGSizeMake(MAX(size1.width, size2.width)+40, 15+size1.height+size2.height);
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
